package com.kmproject.haifu.mvp.ui.holder;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.ui.adapter.PopuWindowSelectAddress1Adapter;
import com.kmproject.haifu.mvp.ui.adapter.PopuWindowSelectHxAdapter;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HxSelectHolder {
    @BindView(R.id.popuwindows_seelct_hx_RecyclerView)
    RecyclerView popuwindowsSeelctHxRecyclerView;
    @BindView(R.id.popuwindows_seelct_hx_txt)
    TextView popuwindowsSeelctHxTxt;
    private Context mcontext;
    private PopuWindowSelectHxAdapter adapter;
    private int selectIndex=0;
    private HousePayWayBean selectHousePayWayBean;
    private PopuWindowSelectAddress1Adapter.BtncliickCallBack mbtncliickCallBack;
    public HxSelectHolder(Context context, View view) {
//        R.layout.popuwindows_seelct_hx
                mcontext = context;
        ButterKnife.bind(this, view);
    }

    public void init(List<HousePayWayBean> hxSelectData,PopuWindowSelectAddress1Adapter.BtncliickCallBack btncliickCallBack) {
        if (hxSelectData==null||hxSelectData.isEmpty())
        {
            ArmsUtils.makeText(mcontext,"未获取到户型数据");
            return;
        }
        mbtncliickCallBack=btncliickCallBack;
        hxSelectData.add(0,null);
        popuwindowsSeelctHxRecyclerView.setLayoutManager(new FlowLayoutManager());
        adapter=new PopuWindowSelectHxAdapter(hxSelectData, new PopuWindowSelectAddress1Adapter.BtncliickCallBack() {
            @Override
            public void callBack(int index, Object content) {
                selectIndex=index;
                selectHousePayWayBean=(HousePayWayBean)content;
            }
        });
        popuwindowsSeelctHxRecyclerView.setAdapter(adapter);
        popuwindowsSeelctHxRecyclerView.addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(5)));
        adapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
    }

    @OnClick(R.id.popuwindows_seelct_hx_txt)
    public void onClick() {
        mbtncliickCallBack.callBack(selectIndex,selectHousePayWayBean);
    }
}
